/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RoomTransaction;

import Address.AddressBean;
import Admission.AdmissionBean;
import Category.CategoryBean;
import Country.CountryBean;
import Course.CourseBean;
import Hostel.HostelBean;
import Room.RoomBean;
import State.StateBean;
import Student.StudentBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author mishra
 */
public class getStuDetail extends HttpServlet {

   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Vector<Object> list1=new Vector<Object>();
        try {
            //int a=0;
            int feetype=Integer.parseInt(request.getParameter("ftype"));
            int admissionId=Integer.parseInt(request.getParameter("admiId"));
            StudentBean st=Student.Query.viewSpecific(admissionId);
            
            if(st.getStudentId()!=0)
            {
            AdmissionBean adm=st.getAdmissionBean();
            AddressBean addb=st.getAddressBean();
            CourseBean cob= adm.getCourseBean();
            CategoryBean cab=st.getCategoryBean();
            String unique = "--"+feetype+"--"+admissionId+"--"+adm.getSemester()+"--"+cab.getCategoryId();
            
            
            list1=RoomTransaction.Query.checkAllotedOrNot(admissionId);
            if(!list1.isEmpty())
            {
            Iterator it1=list1.iterator();
            while(it1.hasNext()){
            RoomTransactionBean rtb=(RoomTransactionBean) it1.next();
            if(rtb.getRoomStatus()==1)
            {
            RoomBean rb=rtb.getRoomBean();
                out.println("<div style='margin-top: 80px;'>");
                out.println("<legend>Allotment Details</legend>");
                out.println("<center><h4 style='color: red'>Room Already Alloted</h4></center>");
                out.println("</div>");
            out.println("<div id='lside' style='float: left; margin-top: 30px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Hostel ID:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='hsid' name='hsid' value='"+rtb.getHostelId()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Room Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='romno' name='romno' value='"+rb.getRoomNo()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            
             out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 30px'>");
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Date of Alloted:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='adate' name='adate' value='"+rtb.getDoa()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Bed Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='bno' name='bno' value='"+rb.getBedNumber()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            }
            else
            {
               
            out.println("<legend>Student Details</legend>");
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+st.getStudentName()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Category:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+cab.getCategory()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Semester:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+adm.getSemester()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            
            
            out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Course Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='a' name='a' value='"+cob.getCourseName()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Session:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+adm.getStudentSession()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Address1:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+addb.getAddress1()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");

            out.println("<legend>Assign Room And Bed</legend>");
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Hostel Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='hostelid' id='hostelid' onchange='getRoomNumber(this.value)'>");
            out.println("<option value=''>Select Hostel</option>");
                   Vector<Object> list = Hostel.Query.ViewAll();
                   Iterator it = list.iterator();
                   while (it.hasNext()) {
                   HostelBean hb = (HostelBean) it.next();
            out.println("<option value='"+hb.getHotelId()+"'>"+hb.getHostelName()+"</option>'");
                       }
            out.println("</select>");                                        
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Bed Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='bedno' id='bedno'></select>");
            out.println("</div>");
            out.println("</div>");
             out.println("</div>");
             
             out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
             
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Room Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='roomid' id='roomid' onchange='getBeds(this.value)'></select>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>"); 
            }
            }
            }
            else
            {  
            if(StudentFeesDetail.Query.countFeeDetails(unique))
            {
            out.println("<legend>Student Details</legend>");
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+st.getStudentName()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Category:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+cab.getCategory()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Semester:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+adm.getSemester()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            
            
            out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Course Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='a' name='a' value='"+cob.getCourseName()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Student Session:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+adm.getStudentSession()+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Address1:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='b' name='c' value='"+addb.getAddress1()+"'>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");

            out.println("<legend>Assign Room And Bed</legend>");
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Hostel Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='hostelid' id='hostelid' onchange='getRoomNumber(this.value)'>");
            out.println("<option value=''>Select Hostel</option>");
                   Vector<Object> list = Hostel.Query.ViewAll();
                   Iterator it = list.iterator();
                   while (it.hasNext()) {
                   HostelBean hb = (HostelBean) it.next();
            out.println("<option value='"+hb.getHotelId()+"'>"+hb.getHostelName()+"</option>'");
                       }
            out.println("</select>");                                        
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Bed Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='bedno' id='bedno' onchange='getAdditionalAmt(this.value)'></select>");
            out.println("</div>");
            out.println("</div>");
            
             out.println("</div>");
             
             out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
             
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Room Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<select class='required' name='roomid' id='roomid' onchange='getBeds(this.value)'></select>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("<div class='control-group' id='res' style='visibility: hidden'>");            
            out.println("<label for='additionamt' class='control-label''>Additional Amount:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readonly id='aamt' name='aamt' value='0'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("</div>");
            } 
            else
            {
                out.println("<div style='margin-top: 80px;'>");
                out.println("<legend>Assign Room And Bed</legend>");
                out.println("<center><h4 style='color: red'>Fees Not Deposited</h4></center>");
                out.println("</div>");
            }
            }
            }
            else{
                out.println("<div style='margin-top: 80px;'>");
                out.println("<legend>Student Details</legend>");
                out.println("<center><h4 style='color: red'>No Record Found</center></h4></center>");
                out.println("</div>");
            }
            
        }catch(Exception e){
            System.out.println(e);
        }
            finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(getStuDetail.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(getStuDetail.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
